# common 目录 CMakeLists.txt
# 收集所有源文件
file(GLOB_RECURSE COMMON_SOURCES "*.cpp")
file(GLOB_RECURSE COMMON_HEADERS "include/*.h" "include/*.hpp")

#输出头文件与sources文件中分别包含哪些文件
message(STATUS "COMMON_HEADERS包含以下文件:")
foreach(header ${COMMON_HEADERS})
    message(STATUS "  ${header}")
endforeach()

message(STATUS "COMMON_SOURCES包含以下文件:")
foreach(source ${COMMON_SOURCES})
    message(STATUS "  ${source}")
endforeach()

# 创建公共库
add_library(common_lib SHARED ${COMMON_SOURCES} ${COMMON_HEADERS})

set_target_properties(common_lib PROPERTIES LINKER_LANGUAGE CXX)

# 设置包含目录
target_include_directories(common_lib
    PUBLIC
    ${CMAKE_CURRENT_SOURCE_DIR}/include
)

# 查找 Boost
cmake_policy(SET CMP0167 NEW)
find_package(Boost REQUIRED COMPONENTS filesystem) # 指定需要的 Boost 组件

if(Boost_FOUND)
    message(STATUS "Boost found: ${Boost_VERSION_STRING}")
    target_include_directories(common_lib
        PUBLIC ${Boost_INCLUDE_DIRS}
    )

    target_link_libraries(common_lib
        PUBLIC ${Boost_LIBRARIES})
else()
    message(FATAL_ERROR "Boost not found")
endif()

# 链接第三方库 - 更新为使用3rdparty_libs接口目标
target_link_libraries(common_lib
    PUBLIC sqlite_orm sqlite3 spdlog
)

# 设置安装规则
install(TARGETS common_lib
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
)
install(DIRECTORY include/
    DESTINATION include/common
    FILES_MATCHING PATTERN "*.h" PATTERN "*.hpp"
)

# 输出提示信息
message(STATUS "已配置 common 库")
